<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('系统管理员操作界面')"/>
    <!--<th:block th:include="include :: bootstrap-select-css"/>-->
    <!--<th:block th:include="include :: jasny-bootstrap-css"/>-->
    <!--<th:block th:include="include :: datetimepicker-css"/>-->
    <link th:href="@{/ruoyi/css/font-awesome.css}" rel="stylesheet"/>
    <link th:href="@{/ruoyi/css/jquery-confirm.min.css}" rel="stylesheet"/>
</head>
<style type="text/css">
    @media screen and (max-width: 768px) {
    }

    /**电脑屏幕下显示***/
    @media screen and (min-width: 768px) {
        body {
            /*text-align:center;*/
            margin: 0px auto;
        }
    }
</style>
<body class="gray-bg">
<!--编辑模态框开始-->
<div class="modal fade" id="sbUpdateModal" tabindex="-1" role="dialog" aria-hidden="true"
     data-keyboard="false">
    <div class="modal-dialog modal-sm">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span>
                </button>
                <h1 class="modal-title"><strong>添加公司名称</strong></h1>
            </div>
            <div class="modal-body">
                <form id="form-sb-update" class="form-horizontal">
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">公司编码</label>
                            <div class="col-sm-8">
                                <input name="gsid" id="gsid_up" readonly="readonly" class="form-control" type="text"
                                       placeholder="请输入公司ID编码"
                                       required="required">
                                <input id="gsid_yc" class="form-control" type="hidden">
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">公司名称</label>
                            <div class="col-sm-8">
                                <div class="input-group">
                                    <input name="gs" id="gs_up" class="form-control" type="text" placeholder="请输入公司名称"
                                           required="required">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="form-group">
                            <div class="modal-footer">
                                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                                <button type="button" class="btn btn-white" id="sb_update_btn" onclick="updatesb()">更新
                                </button>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<div><input type="hidden" id="_pageNumber"></div>
<div><input type="hidden" id="_pageSize"></div>
<p id="pgsid" style="display: none">[[${session.gsid}]]</p>
<p id="pusername" style="display: none">[[${session.username}]]</p>
<th:block th:include="include :: footer"/>
<script th:src="@{/ruoyi/js/jquery-confirm.min.js}"></script>
<script th:inline="javascript">
    $(document).ready(function () {
        initUserTable();
    })

    function initUserTable() {
        $("#bootstrap-table").bootstrapTable({
            showFooter: true,//是否显示页脚，主要用途是显示汇总的信息
            striped: false,//是否显示行间隔色
            paginationPreText: '上一页',
            paginationNextText: '下一页',
            queryParamsType: '',
            method: 'GET',
            uniqueId: "id",
            pageNumber: 'form' ? 1 : parseInt($('#_pageNumber').val()),
            pagination: true,//是否分页
            sidePagination: 'server',//server:服务器端分页|client：前端分页
            pageSize: 'form' ? 10 : parseInt($('#_pageSize').val()),//单页记录数
            pageList: [10, 20, 30, 'ALL'],//可选择单页记录数
            queryParams: queryParams,
            // onDblClickRow: function (row,index) {
            //     console.log(index[0])
            // },
            url: "/sbgl/fwdzb/getfwdzbbygsid/",
            columns: [{
                checkbox: true
            },
                {
                    field: 'no',
                    title: '序号',
                    align: "center",
                    width: 60,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },
                {
                    field: 'gsid',
                    title: '公司编码'
                },
                {
                    field: 'gs',
                    title: '公司名称'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var id = index;
                        var result = "";
                        result += "<a href='javascript:;' class='btn btn-xs blue'  onclick=\"EditViewById('" + row + "','" + id + "')\" title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
                        return result;
                    }
                }]
        })
    }

    function queryParams(params) {
        var param = {
            limit: params.limit, // 页面大小
            offset: params.offset, // 页码
            nextPage: params.pageNumber,
            pageNumber: params.pageNumber,
            pageSize: params.pageSize,
            gsid: $("#pgsid").text(),
            // bfbs: $("#is_bf").val(),
        };
        return param;
    }

    //查询按钮事件
    $('#search_btn').click(function () {
        refresh()
    });

    function refresh() {
        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;
        //获取当前是第几页
        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber;
        $("#_pageNumber").val(pageNumber)
        $("#_pageSize").val(pageSize)
        $('#bootstrap-table').bootstrapTable('refresh', {
            pageNumber: pageNumber,
            pageSize: pageSize
        });
    }

    function addgsmc() {
        $("#sbAddModal").modal({
            backdrop: "static"
        });
        $("#gsid_add").val("")
        $("#gs_add").val("")
    }

    function savesb() {
        // $.ajax({
        //     url: "/sbgl/gsxxb/insertgsxxb",
        //     type: 'POST',
        //     data: $("#sbAddModal form").serialize(),
        //     success: function (result) {
        //         if (result != null) {
        //             $("#sbAddModal").modal('hide');
        //             refresh()
        //             $.alert("添加成功！！！","温馨提示");
        //         }
        //     }
        // });
        var gsid = $("#gsid_add").val()
        var gsmc = $("#gs_add").val()
        if (gsid.length <= 5 || gsmc.length <= 5) {
            $.alert("公司编码与公司名称的长度不能小于6", "温馨提示")
            return false;
        }
        var isgsid = cfpd("/sbgl/gsxxb/getgsxxbbygsid/", gsid)
        var isgsmc = cfpd("/sbgl/gsxxb/getgsmcbygsmc/", gsmc)
        if (isgsid != "") {
            $.alert("公司编码已存在，名称为：" + isgsid[0].gs, "温馨提示")
            return false;
        }
        if (isgsmc != "") {
            $.alert('公司名称已存在,编码为：【' + isgsmc[0].gsid + '】,是否继续？', '温馨提示')
            return false;
        }
        $.confirm({
            title: '温馨提示',
            content: '是否添加？',
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: '/sbgl/gsxxb/insertgsxxb',
                            method: 'POST',
                            data: $("#sbAddModal form").serialize()
                        }).done(function (response) {
                            $("#sbAddModal").modal('hide');
                            $.alert("添加成功", "温馨提示")
                            refresh()
                        }).fail(function () {
                        });
                    }
                },
                取消: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
    }

    function EditViewById(row, index) {
        var data = JSON.stringify($("#bootstrap-table").bootstrapTable('getData')); //获取全部数据
        var data_json = JSON.parse(data);
        $("#emp_update_btn").val(data_json[index].gsid);
        $('#sbUpdateModal').modal('show');
        $('#gsid_up').val(data_json[index].gsid)
        $('#gs_up').val(data_json[index].gs)
        $('#gsid_yc').val(data_json[index].id)
    }

    function updatesb() {
        var gsid= $('#gsid_up').val()
        var gsid01 = $('#gsid_yc').val()
        var gsmc=$("#gs_up").val()
        var isgsmc = cfpd("/sbgl/gsxxb/getgsmcbygsmc/", gsmc)
        if (gsmc.length<=5){
            $.alert("公司名称的长度不能小于6","温馨提示")
            return false
        }
        if (isgsmc!=""){
            $.alert('公司名称已存在,编码为：' + isgsmc[0].gsid,'温馨提示')
            return false
        }
        $.confirm({
            title: '温馨提示',
            content: '是否继续更新公司名称？',
            buttons: {
                确定: {
                    text: '确定',
                    btnClass: 'btn-blue',
                    action: function () {
                        return $.ajax({
                            url: '/sbgl/gsxxb/updategsxxb/'+gsid01,
                            method: 'PUT',
                            data: $("#sbUpdateModal form").serialize()
                        }).done(function (response) {
                            $("#sbUpdateModal").modal('hide');
                            $.alert("更新成功", "温馨提示")
                            refresh()
                        }).fail(function () {
                        });
                    }
                },
                取消: {
                    text: '取消',
                    btnClass: 'btn-red',
                    action: function () {
                    },
                },
            },
        });
    }
</script>
</body>
</html>